const path = require('path')
const config = require('./src/config')

const resolve = (dir) => path.join(__dirname, dir)

module.exports = {
  outputDir: config.outputDir,
  publicPath: config.publicPath,
  assetsDir: config.assetsDir,
  productionSourceMap: false,
  lintOnSave: false,
  devServer: {
    open: false,
    port: config.devPort,
    https: false,
    proxy: {
      [config.proxyApi]: {
        target: config.proxyUrl,
        changeOrigin: true,
        ws: true,
        pathRewrite: {
          [`^${config.proxyApi}`]: '',
        },
      },
    },
    disableHostCheck: true,
  },
  chainWebpack: (config) => {
    config.resolve.alias
      .set('@', resolve('src'))
      .set('@c', resolve('src/components'))
      .set('@p', resolve('src/packages'))
      .set('@u', resolve('src/utils'))
  },
  pages: {
    index: {
      entry: 'src/main.js',
      template: 'public/index.html',
      filename: 'index.html',
      title: config.title,
    },
  },
}
